package design_8_filter.demo1;

import design_8_filter.demo1.entity.User;
import design_8_filter.demo1.filter.UserFilter;
import design_8_filter.demo1.filter.impl.UserAgeFilter;
import design_8_filter.demo1.filter.impl.UserStateFilter;
import design_8_filter.demo1.filter.impl.UserUserNameFilter;

import java.util.ArrayList;
import java.util.List;

public class UserFilterDemo {
	public static void main(String[] args) {
		List<User> users = new ArrayList<User>();
		users.add(new User("王一", 15, 0));
		users.add(new User("王二", 12, 0));
		users.add(new User("王三", 20, 0));
		users.add(new User("王四", 18, 1));
		users.add(new User("王五", 13, 0));

		// 获取过滤器
		// UserAgeFilter       过滤 age >=20 的数据
		// UserStateFilter     过滤 state=1 的数据
		// UserUserNameFilter  过滤 name=王五 的数据
		UserFilter userAgeFilter = new UserAgeFilter(new UserStateFilter(new UserUserNameFilter()));
		List<User> users1 = userAgeFilter.filter(users);
		System.out.println(users1.toString());
	}
}